﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace WMI.NET.CIM
{
    /// <summary>
    /// Defines a connection that is currently communicating, or is configured to communicate, between two service access points. It is used when the connection is not handled as a managed element itself (that is, with Status, statistics, and so on), but its existence is known. A service access point (SAP) that is connected typically operates at the same networking or application layer.
    /// </summary>
    public class CIM_ActiveConnection : CIM_SAPSAPDependency
    {

        private CIM_ServiceAccessPoint _Antecedent;
        private CIM_ServiceAccessPoint _Dependent;
        private Nullable<UInt16> _TrafficType;
        private string _OtherTrafficDescription;
        private Nullable<Boolean> _IsUnidirectional;

        /// <summary>
        /// A SAP that is configured to communicate or is actively communicating with the dependent SAP. In a unidirectional connection, this is the transmitting SAP.
        /// </summary>
        public new CIM_ServiceAccessPoint Antecedent { get { return _Antecedent; } }

        /// <summary>
        /// A second SAP that is configured to communicate or is actively communicating with the antecedent SAP. In a unidirectional connection, this is the receiving SAP.
        /// </summary>
        public new CIM_ServiceAccessPoint Dependent { get { return _Dependent; } }

        /// <summary>
        /// Note: The use of this element is deprecated because it is incorrectly placed on the association. Unicast, broadcast, or other traffic types are not a function of the connection between the referenced endpoints, but rather are a function of the addressing, protocol, and basic functionality of the endpoints. Deprecated description: The type of traffic that is carried over this connection.
        /// </summary>
        public Nullable<UInt16> TrafficType { get { return _TrafficType; } } //TODO enum

        /// <summary>
        /// Note: The use of this element is deprecated because it is incorrectly placed on the association. Unicast, broadcast, or other traffic types are not a function of the connection between the referenced endpoints, but rather are a function of the addressing, protocol, and basic functionality of the endpoints. Deprecated description: A string that describes the type of traffic that is being carried over this instance when its Type property is set, for example, to 1 (Other).
        /// </summary>
        public string OtherTrafficDescription { get { return _OtherTrafficDescription; } }

        /// <summary>
        /// TRUE indicates that this connection is unidirectional; FALSE indicates that this connection is bidirectional. When the connection is unidirectional, the "speaker" should be defined as the antecedent reference. In a bidirectional connection, the selection of which access point is the antecedent or dependent is immaterial.
        /// </summary>
        public Nullable<Boolean> IsUnidirectional { get { return _IsUnidirectional; } }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public CIM_ActiveConnection(ManagementBaseObject mbo)
            : base(mbo)
        {
            _Antecedent = new CIM_ServiceAccessPoint(mbo);
            _Dependent = new CIM_ServiceAccessPoint(mbo);
            _TrafficType = mbo.GetUshortValue("TrafficType");
            _OtherTrafficDescription = mbo.GetStringValue("OtherTrafficDescription");
            _IsUnidirectional = mbo.GetBoolValue("IsUnidirectional");
        }
    }

}
